package com.innovations.inn.service.impl;

import com.innovations.common.utils.uuid.IdGeneratorSnowflake;
import com.innovations.inn.domain.ColumnClassify;
import com.innovations.inn.mapper.ColumnClassifyMapper;
import com.innovations.inn.service.IColumnClassifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 栏目分类Service业务层处理
 *
 * @author dp
 * @date 2024-08-10
 */
@Service
public class ColumnClassifyServiceImpl implements IColumnClassifyService {
    @Autowired
    private ColumnClassifyMapper columnClassifyMapper;
    @Autowired
    private IdGeneratorSnowflake idGeneratorSnowflake;

    /**
     * 查询栏目分类
     *
     * @param classifyId 栏目分类主键
     * @return 栏目分类
     */
    @Override
    public ColumnClassify selectColumnClassifyByClassifyId(Long classifyId) {
        return columnClassifyMapper.selectColumnClassifyByClassifyId(classifyId);
    }

    /**
     * 查询栏目分类列表
     *
     * @param columnClassify 栏目分类
     * @return 栏目分类
     */
    @Override
    public List<ColumnClassify> selectColumnClassifyList(ColumnClassify columnClassify) {
        return columnClassifyMapper.selectColumnClassifyList(columnClassify);
    }

    /**
     * 新增栏目分类
     *
     * @param columnClassify 栏目分类
     * @return 结果
     */
    @Override
    public int insertColumnClassify(ColumnClassify columnClassify) {
        return columnClassifyMapper.insertColumnClassify(columnClassify);
    }

    /**
     * 修改栏目分类
     *
     * @param columnClassify 栏目分类
     * @return 结果
     */
    @Override
    public int updateColumnClassify(ColumnClassify columnClassify) {
        return columnClassifyMapper.updateColumnClassify(columnClassify);
    }

    /**
     * 批量删除栏目分类
     *
     * @param classifyIds 需要删除的栏目分类主键
     * @return 结果
     */
    @Override
    public int deleteColumnClassifyByClassifyIds(Long[] classifyIds) {
        return columnClassifyMapper.deleteColumnClassifyByClassifyIds(classifyIds);
    }

    /**
     * 删除栏目分类信息
     *
     * @param classifyId 栏目分类主键
     * @return 结果
     */
    @Override
    public int deleteColumnClassifyByClassifyId(Long classifyId) {
        return columnClassifyMapper.deleteColumnClassifyByClassifyId(classifyId);
    }

    /**
     * 实体数据补全
     *
     * @param columnClassify 实体
     * @param userId         用户id
     * @param crateType      创建类型 1：新增 2：修改
     */
    @Override
    public void completeData(ColumnClassify columnClassify, Long userId, Integer crateType) {
        //主键
        if (columnClassify.getClassifyId() == null || "".equals(columnClassify.getClassifyId())) {
            columnClassify.setClassifyId(idGeneratorSnowflake.nextId());
        }
    }
}
